﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using FileHelpers;

public sealed class DataUploadVariables
{
    public static DataUploadVariables Instance
    {
        get
        {
            if (System.Web.HttpContext.Current.Session["DataUploadVariables"] == null)
                System.Web.HttpContext.Current.Session["DataUploadVariables"] = new DataUploadVariables();

            return (DataUploadVariables)System.Web.HttpContext.Current.Session["DataUploadVariables"];
        }
    }

    private static String tableName4DataUpload;
    public static String Table4DataUpload
    {
        get
        {
            if (String.IsNullOrEmpty(tableName4DataUpload))
                tableName4DataUpload = "CarSalesData";
            setFileEngine();
            return tableName4DataUpload;
        }
        set
        {
            tableName4DataUpload = value;
            setFileEngine();
        }
    }

    public static String[] GenTableList = { "EmployerName", "SchemeCode", "PromotionScheme", "ChannelCode", "ModeOfPayment" };

    public static DelimitedFileEngine fileEngine { get; private set; }
    private static void setFileEngine()
    {
        fileEngine = null;
        if (tableName4DataUpload == "CarSalesData")
            fileEngine = new DelimitedFileEngine(typeof(TableStructures.CarSalesData));
        else if (tableName4DataUpload == "CityCategory")
            fileEngine = new DelimitedFileEngine(typeof(TableStructures.CityCategory));
        else if (tableName4DataUpload == "DMAMaster")
            fileEngine = new DelimitedFileEngine(typeof(TableStructures.DMAMaster));
        else if (tableName4DataUpload == "Segments")
            fileEngine = new DelimitedFileEngine(typeof(TableStructures.Segments));
        else if (tableName4DataUpload == "Source")
            fileEngine = new DelimitedFileEngine(typeof(TableStructures.Source));
        else if (tableName4DataUpload == "AgentMaster")
            fileEngine = new DelimitedFileEngine(typeof(TableStructures.AgentMaster));
        else if (tableName4DataUpload == "TaxMaster")
            fileEngine = new DelimitedFileEngine(typeof(TableStructures.TaxMaster));
        else if (GenTableList.Contains(tableName4DataUpload))
            fileEngine = new DelimitedFileEngine(typeof(TableStructures.GenTable));
        else
            throw new Exception("Cannot initialize File Reader. Invalid Product Name.");
        return;
    }

    public static DataTable UploadData { get; set; }
    public static DataTable RejectedData { get; set; }
    public static DataTable ErrorData { get; set; }

}
